package dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import pojo.Book;
import util.DButil;
import dao.BookDao;

public class BookDaoImpl implements BookDao{

	@Override
	public List<Book> getAllBooks(Connection conn) {
		List<Book> list=new ArrayList<Book>();
		ResultSet rs=null;
		String sql="select * from books";
		try {
			PreparedStatement pst=conn.prepareStatement(sql);
			rs=pst.executeQuery();
			while (rs.next()) {
				Book book=new Book();
				book.setId(rs.getInt("bid"));
				book.setName(rs.getString("bname"));
				list.add(book);				
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		return list;
	}
}
